package com.eslserver.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.eslserver.core.config.AttachmentConfig;

public class FileUploadUtil {
	public static final Logger LOG = LoggerFactory
			.getLogger(FileUploadUtil.class);

	public static String GetFileRowString(String filename, String contentType,
			long filesize, String downloadUrl) {
		return new String("{\"name\":\"" + filename + "\",\"type\":\""
				+ contentType + "\",\"size\":\"" + filesize
				+ "\",\"downloadURL\":\"" + downloadUrl + "\"}");
	}

	public static String GetDownloadURL(String fileFullPath) {
		String backslash = System.getProperty("file.separator");
		String downloadUrl = fileFullPath;
		try {
			downloadUrl = new String(
					fileFullPath.substring(AttachmentConfig.tomcatPath.length()))
					.replace(backslash, "/");
		} catch (IndexOutOfBoundsException e) {
			LOG.error(e.getMessage(), e);
		}
		return downloadUrl;
	}
}